package com.burntsky.xbmc.android;


import java.util.ArrayList;

import org.xbmc.api.object.Movie;
import org.xbmc.api.object.TvShow;

import android.app.ListFragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MovieListFragment extends ListFragment {

	private XbmcController _Controller;
	
	public MovieListFragment(XbmcController controller){
		this._Controller = controller;
	}
	
	/* (non-Javadoc)
	 * @see android.app.ListFragment#onActivityCreated(android.os.Bundle)
	 */
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		new AsyncTask<Void, Void, ArrayList<Movie>>(){
			@Override
			protected ArrayList<Movie> doInBackground(Void...voids) {
				return MovieListFragment.this._Controller.GetMovies();
			}			
			@Override
			protected void onPostExecute(ArrayList<Movie> result) {
				//HelloAndroid.this.mMyButton.setText(result);
				ArrayList<String> showNames = new ArrayList<String>();
				for(int i=0;i<result.size();i++){
					showNames.add(result.get(i).title);
				}
				MovieListFragment.this.setListAdapter(new ArrayAdapter<String>(MovieListFragment.this.getActivity(),
						R.layout.title_list_item, showNames));
			}

		}.execute();

	}

	/* (non-Javadoc)
	 * @see android.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long)
	 */
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		
		//this.getActivity().getActionBar().hide();
	}

}
